 package org.magento.pages;

import org.magento.utils.ConfigProperties;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;


//page located /admin/dashboard/ - Magento Admin panel

public class Dashboard extends Page {
	
	//Locators:
	@FindBy (className = "link-logout")
	public WebElement logOut;
	
	@FindBy (xpath = "/html/body/div/div/div[3]/ul/li[2]/a/span")
	public WebElement salesMenu;
	
	@FindBy (xpath = "//a[contains(.,'Orders')]")
	public WebElement ordersSubMenu;
	
	@FindBy (xpath = "/html/body/div/div/div[3]/ul/li[5]/a/span")
	public WebElement customerMenu;
	
	@FindBy(xpath = "//a[contains(.,'Manage Customers')]")
	public WebElement manageCustomersSubmenu;
	


	//Functions:
	public ManageCustomers gotoManageCustomers() throws Exception  {
		Actions action = new Actions(driver);
		action.moveToElement(customerMenu).build().perform();
		waitForFiveSeconds();
		manageCustomersSubmenu.click();
		return PageFactory.initElements(driver, ManageCustomers.class);
	}
	
	public OrdersBeckEnd gotoOrders() throws Exception {
		Actions action = new Actions(driver);
		action.moveToElement(salesMenu).build().perform();
		waitForFiveSeconds();
		ordersSubMenu.click();
		return PageFactory.initElements(driver, OrdersBeckEnd.class);
		
	}
	
	public void logOut() {
		logOut.click();		
	}
	
	//Assertions:
	public boolean isLoggedIn() {
		return isElementPresent(logOut);
	}
	
	//Auto - generated
	@Override
	public void open() {	
		driver.get(ConfigProperties.getProperty("url.be"));	
	}
	
	public Dashboard(WebDriver driver) {
		super(driver);
	}


}
